<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const indices = [];
        const array = ['a', 'a', 'a', 'a', 'a', 'a'];
        const element = 'a';
        let idx = array.indexOf(element);
        while (idx !== -1) {
            indices.push(idx);
            idx = array.indexOf(element, idx + 1);
        }
        console.log(indices);
// [0, 2, 4]
    </script>
</body>

</html>